Ext.define('EducationInfo', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
		, "EducationType"   //教育类型
		, "EducationName"   //教育名称
		, "School"   //学校
		, "Major"   //专业
		, "StudyTime"   //研读时间
		, "Certificate"   //证书
		, "CertAuthority"   //颁证单位
		, "CertDate"   //颁证日期
		, "Period"   //有效期
        , "EmpId"   //员工Id
        , "EmpName"   //员工姓名
	],
    idProperty: "Id"
});

Ext.define('SHApp.EmployeeInfo.EducationInfo.Grid', {
    extend: 'BLBTSystem.grid',
    alias: 'shapp.employeeinfo.grid',
    requires: ['SHApp.EmployeeInfo.EducationInfo.Form'],
    txtEducationTypeID: 'txtEducationType',
    txtEducationNameID: "_txtEducationNameID",
    dataModel: "EducationInfo",
    dataUrl: "api/educationinfo?format=json",
    empId: "",
    empName: "",
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        me.txtEducationTypeID += me.id;
        me.txtEducationNameID += me.id;
        this.creatTbar();
        this.creatColumns();
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    creatColumns: function () {
        var me = this;
        me.columns = [{
            text: "Id",
            flex: 1,
            dataIndex: 'Id',
            sortable: false,
            hidden: true
        }, {
            text: "教育类型",
            width: 100,
            dataIndex: 'EducationType',
            sortable: true
        }, {
            text: "教育名称",
            width: 100,
            dataIndex: 'EducationName',
            sortable: true
        }, {
            text: "学校",
            width: 150,
            dataIndex: 'School',
            sortable: true
        }, {
            text: "专业",
            width: 150,
            dataIndex: 'Major',
            sortable: true
        }, {
            text: "研读时间",
            width: 100,
            dataIndex: 'StudyTime',
            sortable: true
        }, {
            text: "证书",
            width: 100,
            dataIndex: 'Certificate',
            sortable: true
        }, {
            text: "颁证单位",
            width: 100,
            dataIndex: 'CertAuthority',
            sortable: true
        }, {
            text: "颁证日期",
            width: 100,
            dataIndex: 'CertDate',
            sortable: true,
            renderer: formatDate
        }, {
            text: "有效期",
            width: 100,
            dataIndex: 'Period',
            sortable: true
        }
		]
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
             Ext.create("BLBTSystem.CmbYesNo", {
                 fieldLabel: "教育类型:",
                 fields: ["text"],
                 data: [["学历"], ["培训"]],
                 valueField: "text",
                 displayField: "text",
                 name: "EducationType",
                 value: "学历",
                 id: me.txtEducationTypeID,
                 maxLength: 50,
                 labelWidth: 60,
                 width: 180,
                 forceSelection: false
             }), Ext.create("BLBTSystem.CmbYesNo", {
                 fieldLabel: "教育名称:",
                 fields: ["text"],
                 data: [["技校"], ["职高"], ["专科"], ["本科"], ["硕士"], ["博士"], ["在职研究生"]],
                 valueField: "text",
                 displayField: "text",
                 name: "EducationName",
                 value: "技校",
                 id: me.txtEducationNameID,
                 maxLength: 50,
                 labelWidth: 60,
                 width: 180,
                 forceSelection: false
             }), ' ', {
                 xtype: 'button',
                 text: '查询',
                 iconCls: 'icon-btn-search',
                 handler: function () {
                     me.clearFilters();
                     me.addFilter("EmpId", me.empId);
                     var vEducationType = me.down("#" + me.txtEducationTypeID).getValue();
                     if (vEducationType && vEducationType.length > 0) {
                         me.addFilter("EducationType", vEducationType);
                     }
                     var vEducationName = me.down("#" + me.txtEducationNameID).getValue();
                     if (vEducationName) {
                         if (vEducationName.length > 0) {
                             me.addFilter("EducationName", vEducationName);
                         }
                     }
                     me.loadByFilter();
                 }
             }, '->', {
                 xtype: 'button',
                 text: '添加',
                 id: me.btnAddID,
                 iconCls: 'icon-btn-add',
                 handler: function () {
                     var win = me.getForm('SHApp.EmployeeInfo.EducationInfo.Form');
                     win.loadRecord(new EducationInfo({ Id: null, EducationType: "学历", EducationName: "技校", CertDate: new Date(), EmpId: me.empId, EmpName: me.empName }));
                     win.Show("添加");
                 }
             }, ' ', {
                 xtype: 'button',
                 disabled: true,
                 id: me.btnEditID,
                 text: '修改',
                 iconCls: 'icon-btn-edit',
                 handler: function () {
                     var rs = me.getSelectionModel().getSelection();
                     if (rs) {
                         if (rs.length > 0) {
                             rs[0].data.CertDate = formatDate(rs[0].data.CertDate);
                             me.EditData(me.getForm('SHApp.EmployeeInfo.EducationInfo.Form'));
                         }
                     }
                 }
             }, ' ', {
                 xtype: 'button',
                 disabled: true,
                 id: me.btnDeleteID,
                 text: '删除',
                 iconCls: 'icon-btn-delete',
                 handler: function () {
                     me.DeleteData();
                 }
             }
        ]
    }
})

